#ifndef __ANIMATIONMANAGER__
#define __ANIMATIONMANAGER__

//[Headers]     -- You can add your own extra header files here --
#include "../includes/includes.h"

#include "../components/MainComponent.h"
#include "../components/ContainerComponent.h"
#include "../components/ElementComponent.h"
#include "../timers/ChangingStateTimer.h"
#include "../extras/animation/ComponentAnimations.h"
//[/Headers]


class AnimationManager
{
public:
    //==============================================================================
	AnimationManager ()
	{
		AnimationManager(0);
	}

	AnimationManager (MainComponent * mainComponent_) : mainComponent (mainComponent_)
	{
		mouseTimedController = new ChangingStateTimer(mainComponent);
	}

    virtual ~AnimationManager()
	{
		if(mouseTimedController)
		{
			if(mouseTimedController->isTimerRunning())
			{
				mouseTimedController->stopTimer();
			}
			delete mouseTimedController;
		}
	}

	virtual void mouseEnterApp(const MouseEvent& e)
	{
		mouseTimedController->mouseIn();
	}
	
	virtual void mouseEnterElement(ElementComponent * element, const MouseEvent& e)
	{
		animator.changeSize(element->getImageHolder(), 96, 96, 150, false, true);
	}

	virtual void mouseExitApp(const MouseEvent& e)
	{
		mouseTimedController->mouseOut();
	}

	virtual void mouseExitElement(ElementComponent * element, const MouseEvent& e)
	{
		animator.changeSize(element->getImageHolder(), 32, 32, 200, false, true);
	}

	virtual void mouseMoveOnApp(const MouseEvent& e)
	{
	
	}

	virtual void mouseMoveOnElement(const MouseEvent& e)
	{
	
	}

	virtual void mouseDownOnApp(const MouseEvent& e)
	{
	
	}

	virtual void mouseDownOnElement(ElementComponent * element, const MouseEvent& e)
	{
	
	}

	virtual void mouseUp(Component * comp, const MouseEvent& e)
	{
	}

	virtual void mouseDragApp(const MouseEvent& e)
	{
	
	}

	virtual void mouseDragElement(ElementComponent * element, const MouseEvent& e)
	{
		/*
		MouseEvent evt (e.getEventRelativeTo(mainComponent));
		Component * target = mainComponent->getComponentAt(evt.x, evt.y);

		if(dynamic_cast<ElementComponent*> (target) != 0)
		{
			ElementComponent * temp = dynamic_cast<ElementComponent*> (target);	
			if(temp->getContainer() == element->getContainer())
			{
				if(e.x > temp->getWidth() / 3 && e.x < temp->getWidth() * 2 / 3 && temp != target)
				{
					if(temp->getX() < element->getX())
					{
						temp->setTopLeftPosition(temp->getX() + temp->getWidth() /2, temp->getY());
					}
					else
					{
						temp->setTopLeftPosition(temp->getX() - temp->getWidth() /2, temp->getY());
					}
				}
			}
		}
		*/
	}

	virtual void mouseDoubleClickOnApp(const MouseEvent &e)
	{
	
	}

	virtual void mouseDoubleClickOnElement(const MouseEvent &e)
	{
	
	}

	virtual void mouseClickOnApp(const MouseEvent &e)
	{
	
	}

	virtual void mouseClickOnElement(const MouseEvent &e)
	{
	
	}

	virtual void endDraggingElement(ElementComponent * element, const MouseEvent& e)
	{
	}

//==============================================================================
//    juce_UseDebuggingNewOperator
  
protected:
	MainComponent * mainComponent;

	ChangingStateTimer * mouseTimedController;

	SuperComponentAnimator animator;

};


#endif 
